package com.my.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.my.annotation.SystemErrorLog;
import com.my.annotation.SystemOperatorLog;
import com.my.common.GetAddressByIp;
import com.my.constant.ErrorCode;
import com.my.exception.BusinessException;
import com.my.service.EmployeeService;
import com.my.service.LeaveBillService;
import com.my.util.IPUtil;

/**
 * 用于跳转页面
 * 
 * @author wb-zc189961
 *
 */
@Controller
@RequestMapping(value="/index")
public class IndexAction {
	private static final Logger logger = LoggerFactory.getLogger(IndexAction.class);
	@Resource
	private LeaveBillService leaveBillService;
	@Resource
	private EmployeeService employeeService;
	
	/**
	 * 去首页
	 * 
	 * @return
	 */
	@RequestMapping(value = "/index")
	public String gotoIndex(HttpServletRequest request) {
		String ip="";
		ip=IPUtil.getRemoteHost(request);
		if(ip.equals("127.0.0.1")){
			request.getSession().setAttribute("locate", "本机IP，无法获取地址");
		}else{
			String locate=GetAddressByIp.getAddressByIp(ip);
			request.getSession().setAttribute("locate", locate);
		}
		return "common/index";
	}
	
	/**
	 * 去登陆页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/to_login")
	public String gotoLogin() {
		return "login";
	}

	/**
	 * 请假管理的欢迎页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/leave_welcome")
	@SystemErrorLog(description="测试一下")
	public String gotoLeaveWelcome() {
		throw new RuntimeException("尼玛，怎么这么难搞，测试一下 IndexAction");
	}
	
	@RequestMapping(value = "/testOperateLog")
	@SystemOperatorLog(description="测试一下")
	public String testOperateLog() {
		return "uEditor/uEditor";
	}
	
	
	@RequestMapping(value = "/test1")
	public String testSpringMvcExceptionHandle() throws BusinessException {
		throw new BusinessException(ErrorCode.DEPLOY_ID_NOT_EXIST,"测试一下业务异常");
	}
	
	@RequestMapping(value = "/test2")
	public String testSpringMvcExceptionHandle2() throws BusinessException {
		throw new BusinessException(ErrorCode.NOT_DATA_FOUND,"没有数据");
	}
	@RequestMapping(value = "/test3")
	public String testLog() {
		logger.trace("测试trace");
		logger.debug("测试debug");
		logger.info("测试info");
		logger.warn("测试warn");
		logger.error("测试error");
		return "uEditor/uEditor";
	}
	@RequestMapping(value = "/test4")
	public String testSpringJsonParam(@RequestBody String[] test){
		System.out.println(test);
		return "uEditor/uEditor";
	}
}